home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1990 September: Essentials 4 / ADC Developer CD (1990-09) [Essentials 4]_iso / Developer Essentials 4.iso / d e v e l o p / develop 4 code / A:ROSE / MCPMBƒ / MBosmain.c / MBosmain.c
Encoding:
Text File  |  1990-08-28  |  4.7 KB  |  194 lines  |  [TEXT/MPS ]

  1. /*------------------------------------------------------------------------------
  2. #
  3. #    MBosmain.c
  4. #
  5. #    Example of an A/ROSE task, to be linked with "MBosmain.c.o"
  6. #  and downloaded to a MCP card.
  7. #
  8. #  Registers itself with 
  9. #  object_name  "MBTask"  and
  10. #  type_name    "MBServer".
  11. #
  12. #  The "Exercise" application in this same folder will then find
  13. #  this task on a MCP card, and use it for parallel processing
  14. #  (if the "MCP" checkbox is checked).
  15. #  Look at the source code Exercise.c for more details about the 
  16. #  distributed Mandelbrot computation.
  17. #
  18. #    Components:
  19. #                MBosmain.c
  20. #                iter16.a
  21. #                MBTask.c
  22. #
  23. ------------------------------------------------------------------------------*/
  24. /* -------------- MPW: select the following lines + <ENTER> ------
  25. Asm iter16.a
  26. C MBosmain.c -r
  27. C MBTask.c   -r
  28. link -t 'DMRP' -c 'RWM ' ∂
  29.     MBosmain.c.o ∂
  30.     MBTask.c.o ∂
  31.     iter16.a.o ∂
  32.     ::OS.o ∂
  33.     ::osglue.o ∂
  34.     -o start
  35.     
  36. ::Download start
  37. ---------------------------------------------------------------- */
  38.  
  39.  
  40. // the following definitions come from the A/ROSE include file "os.h"
  41.  
  42. typedef long tid_type;
  43.  
  44. struct ST_Registers
  45. {
  46.     long    D_Registers [8];        // D0 - D7 
  47.     long    A_Registers [8];        // A0 - A7  Note: A7 not used
  48.     long    PC;                        // Program Counter
  49. };
  50.  
  51. struct ST_PB
  52. {
  53.     char    *CodeSegment;            // memory region on card for code
  54.     char    *DataSegment;            // memory region on card for global data
  55.     char    *StartParmSegment;        // memory region on card for start parameters
  56.     struct    ST_Registers InitRegs;    // initial register set for starting task
  57.     long    stack;                    // initial stack size (in bytes)
  58.     long    heap;                    // initial heap size (in bytes)
  59.     short    return_code;            // error code if task not started (Tid = 0)
  60.     unsigned char priority;            // priority of task (in bytes)
  61.     tid_type    ParentTID;            // TID of Parent on Network/Host
  62. };
  63.  
  64. typedef struct ST_PB ST_PB;
  65.  
  66.  
  67.  
  68. // the following declarations come from arose.h
  69.  
  70. typedef unsigned long     OSlong;
  71. typedef unsigned short     OSshort;
  72. typedef unsigned char     OSchar;
  73.  
  74. //    gCommon - A/ROSE common data area
  75.  
  76. struct    gCommon        //    Located at 0x400 on the MCP card
  77. {
  78.     OSshort    gRelease;            //    release and version number
  79.     OSchar    gProcessor;            //    Type of processor        
  80.     OSchar    gCardRun;            //    Set zero by download, non-zero by O/S
  81.     OSshort    gBoardID;            //    Board id of card        
  82.     OSlong    gTID;                //    Current Task ID            
  83.     OSchar    gDebugOn;            //    non-zero if debugger running        
  84.     OSchar    gMajorFlag;            //    major processing flag    
  85.     OSlong    gInitA5;            //    Initial A5                
  86.     // ................
  87.     // many, many other fields contained in this structure: look up in arose.h !
  88.     // ................
  89. };
  90.  
  91. typedef struct gCommon gCommon;
  92.  
  93. #define        cMaxMsg        500            //    Maximum number of messages
  94. #define        cOSStack    4096        //    size of OS Stack
  95.  
  96. // the following two lines come from siop.h
  97.  
  98. #define    TICKS_PS    19                //    19 ticks per second    
  99. #define    TICK_MIN_MAJ 8                //   8 minor ticks per major tick
  100.  
  101.  
  102. // prototypes
  103.  
  104. void    osinit ();
  105. void    osstart ();
  106. void    name_server ();
  107. void    ICCM ();
  108. extern    tid_type        GetTID();
  109. extern    struct gCommon    *GetgCommon();
  110. extern    tid_type        StartTask(struct ST_PB *);
  111.  
  112. void    MBTask ();
  113.  
  114. void StartNameServer(ST_PB *pb);    // the Name Manager
  115. void StartICCManager(ST_PB *pb);    // you guess it!
  116. void StartMBTask(ST_PB *pb);        // and our Mandelbrot task
  117.  
  118. pascal void illegal ()
  119.         extern    0x4afc;
  120.  
  121.  
  122. main ()
  123. {
  124.     struct ST_PB stpb;    // Start parameter block
  125.  
  126.     // Init OS with cMaxMsg messages and cStackOS stack
  127.  
  128.     osinit (cMaxMsg, cOSStack);
  129.     
  130.     StartNameServer(&stpb);    // the Name Manager
  131.     StartICCManager(&stpb);    // you guess it!
  132.     StartMBTask(&stpb);        // and our sample task
  133.     
  134.     osstart (TICK_MIN_MAJ, TICKS_PS);    // Start operating system
  135.  
  136.     illegal ();      // should never get here!
  137.  
  138. }
  139.  
  140.  
  141.  
  142. void StartNameServer(ST_PB *pb)
  143. // priority 31, 4k stack, 0 heap
  144. {
  145.     pb -> CodeSegment = 0;
  146.     pb -> DataSegment = 0;
  147.     pb -> StartParmSegment = 0;
  148.     pb -> stack = 4096;
  149.     pb -> heap = 0;
  150.     pb -> priority = 31;
  151.     pb -> InitRegs.PC = name_server;
  152.     pb -> InitRegs.A_Registers [5] = GetgCommon() -> gInitA5;
  153.     pb -> ParentTID = GetTID();
  154.     
  155.     if (StartTask (pb) == 0)
  156.         illegal ();
  157. }
  158.  
  159. void StartICCManager(ST_PB *pb)
  160. // priority 31, 128-byte stack, 0 heap
  161. {
  162.     pb -> CodeSegment = 0;
  163.     pb -> DataSegment = 0;
  164.     pb -> StartParmSegment = 0;
  165.     pb -> stack = 128;
  166.     pb -> heap = 0;
  167.     pb -> priority = 31;
  168.     pb -> InitRegs.PC = ICCM;
  169.     pb -> InitRegs.A_Registers [5] = GetgCommon() -> gInitA5;
  170.     pb -> ParentTID = GetTID();
  171.     
  172.     if (StartTask (pb) == 0)
  173.         illegal ();
  174. }
  175.  
  176.  
  177. void StartMBTask(ST_PB *pb)
  178. // priority 30, 4k stack, 0 heap
  179. {
  180.     pb -> CodeSegment = 0;
  181.     pb -> DataSegment = 0;
  182.     pb -> StartParmSegment = 0;
  183.     pb -> InitRegs.A_Registers [5] = GetgCommon() -> gInitA5;
  184.     pb -> ParentTID = GetTID();
  185.     pb -> stack = 4096;
  186.     pb -> heap = 0;
  187.     pb -> priority = 10;
  188.     pb -> InitRegs.PC = MBTask;    // entry point of Mandelbrot task
  189.  
  190.     if (StartTask (pb) == 0)    // if the task does not get started
  191.         illegal ();                // go debugging
  192. }
  193.  
  194.